﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using MvcShop.Extensions.Html;

namespace MvcShop.Models.ViewDataModels
{
    public class GiftCardViewData
    {
        #region ==== Property =====
        public int PageIndex { get; set; }
        public int Count { get; set; }
        public int Total { get; set; }
        public string KeyWord { get; set; }
        public SelectList AmountList { get; set; }
        public Dictionary<string, object> Parameters { get; set; }

        public GiftCard GiftCard { get; set; }
        public IEnumerable<GiftCard> GiftCards { get; set; }
        #endregion

        #region ==== Methods ====
        public GiftCardViewData WithPageIndex(int pageIndex)
        {
            this.PageIndex = pageIndex;
            return this;
        }

        public GiftCardViewData WithCount(int count)
        {
            this.Count = count;
            return this;
        }

        public GiftCardViewData WithTotal(int pageSize)
        {
            this.Total = Math.Max((this.Count + pageSize - 1) / pageSize, 1); ;
            return this;
        }

        public GiftCardViewData WithKeyWord(string keyWord)
        {
            this.KeyWord = keyWord;
            return this;
        }

        public GiftCardViewData WithAmountList(SelectList amountList)
        {
            this.AmountList = amountList;
            return this;
        }

        public GiftCardViewData WithParameters(Dictionary<string, object> parameters)
        {
            this.Parameters = parameters;
            return this;
        }

        public GiftCardViewData WithGiftCard(GiftCard giftCard)
        {
            this.GiftCard = giftCard;
            return this;
        }

        public GiftCardViewData WithGiftCards(IEnumerable<GiftCard> giftCards)
        {
            this.GiftCards = giftCards;
            return this;
        }
        #endregion
    }

    public static class GiftCardView
    {
        public static GiftCardViewData Data { get { return new GiftCardViewData(); } }
    }
}
